package com.nineclock.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nineclock.common.entity.UserInfo;
import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.common.exception.NcException;
import com.nineclock.common.utils.CurrentUserHolder;
import com.nineclock.system.mapper.SysCompanyUserMapper;
import com.nineclock.system.pojo.SysCompanyUser;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysCompanyUserServiceImpl extends ServiceImpl<SysCompanyUserMapper, SysCompanyUser> implements SysCompanyUserService {


    /**
     * 查询当前企业所有员工
     *
     * @return
     */
    @Override
    public List<SysCompanyUser> selectCompanyUserAll() {

        UserInfo userInfo = CurrentUserHolder.get();

        if (userInfo == null) {
            throw new NcException(ResponseEnum.UNAUTHORIZED);
        }

        Long companyId = userInfo.getCompanyId();
        if (companyId == null || companyId == 0) {
            throw new NcException(ResponseEnum.COMPANY_NOT_FOUND);
        }

        return this.list(Wrappers.<SysCompanyUser>lambdaQuery().eq(SysCompanyUser::getCompanyId, companyId));
    }
}
